package com.usian.model.base;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.usian.model.common.dtos.PageRequestDto;
import com.usian.model.common.dtos.PageResponseResult;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;


public class BaseServiceImpl<M extends BaseMapper<T>,T> extends ServiceImpl<M,T> implements BaseResult {

    protected <P extends PageRequestDto> ResponseResult getPageData(P dto, Wrapper wrapper){
        Page page = new Page(dto.getPage(),dto.getSize());
        IPage result = page(page, wrapper);
        ResponseResult responseResult = new PageResponseResult(dto.getPage(),dto.getSize(),(int)result.getTotal());
        responseResult.setData(result.getRecords());
        return responseResult;
    }

    public ResponseResult getSuccess(){
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    public ResponseResult paramError(){
        return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
    }

    public ResponseResult paramError(String errorRsult){
        return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID,errorRsult);
    }

    public ResponseResult okResult(Object okResult){
        return ResponseResult.okResult(okResult);
    }


}
